package com.platform.modules.wallet.controller;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.RandomUtil;
import cn.hutool.crypto.SecureUtil;
import cn.hutool.http.HttpUtil;
import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.platform.modules.wallet.enums.RedPacketTypeEnum;
import com.platform.modules.wallet.utils.RandSplitNumUtils;
import org.apache.http.HttpResponse;
import com.platform.modules.wallet.utils.HttpUtils;
import org.apache.http.util.EntityUtils;

import java.math.BigDecimal;
import java.math.RoundingMode;
import java.time.LocalDate;
import java.util.*;

public class TestMain {

    public static void main(String[] args) {

        String secret = "ACA36942746044B9BA156B1F28D06D40";

        Date date = DateUtil.date();

        Map<String, Object> params = new TreeMap();
        params.put("mch_id", "E000000011");
        params.put("time", date.toString());
        params.put("walletcode", "68d30a9594728bc39aa24be94b319d21");

        String param = getParam(params);

        System.out.println(param + "key=" + secret);

        String md5 = SecureUtil.md5(param + "key=" + secret);

        System.out.println(param + "sign=" + md5);
//        params.put("sign",md5);

//        String registerUrl="http://www.wkh797.com/home/login";
//
//        String get = HttpUtil.get(registerUrl, params);

//        System.out.println(get);
    }


//    public static void main(String[] args) {
//
//        String secret = "ACA36942746044B9BA156B1F28D06D40";
//
//        Map<String, Object> params = new TreeMap();
//        params.put("mch_id", "E000000011");
//        params.put("phone", "13005761234");
//        params.put("name", "张指导");
//        params.put("nick", "下张");
//
//        StringBuilder s1 = new StringBuilder();
//        for (String key : params.keySet()) {
//            s1.append(key).append("=").append(params.get(key)).append("&");
//        }
//
//        String param = s1.toString();
//
//        String paramKey = param + "key=" + secret;
//
//        System.out.println(paramKey);
//
//        String paramMdd5 = SecureUtil.md5(param + "key=" + secret);
//
//        System.out.println(paramMdd5);
//
//        System.out.println(param + "sign=" + paramMdd5);
//
//        params.put("sign",paramMdd5);
//
//        String registerUrl="http://63.216.193.82:8002/game/register";
//
//        String post = HttpUtil.post(registerUrl, params);
//        //mch_id=E000000011&result_code=0000&result_message=OK&sign=9a2d755795a129dc781e3aaa21280bca&sign_type=MD5&walletcode=68d30a9594728bc39aa24be94b319d21
//
//        System.out.println(post);
//    }


    private static String getParam(Map<String, Object> params) {
        StringBuilder s1 = new StringBuilder();
        for (String key : params.keySet()) {
            s1.append(key).append("=").append(params.get(key)).append("&");
        }
        return s1.toString();
    }

}
